package com.tjn;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class Exercise02 {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(new Car("法拉利", 100000));
        list.add(new Car("保时捷", 200000));
        list.add(new Car("兰博基尼", 300000));

        list.remove(2);
        System.out.println(list);

        System.out.println(list.contains(new Car("兰博基尼", 300000)));

        System.out.println(list.size());

        System.out.println(list.isEmpty());

        list.clear();
        System.out.println(list);

        ArrayList list2 = new ArrayList();
        list2.add(new Car("法拉利", 100000));
        list2.add(new Car("保时捷", 200000));
        list2.add(new Car("兰博基尼", 300000));
        list2.add(new Car("宾利", 100000));
        list.addAll(list2);
        System.out.println(list);

        System.out.println(list.containsAll(list2));

        list.removeAll(list2);
        System.out.println(list);

        list.add(new Car("宾利", 300000));
        list.add(new Car("奔驰", 400000));
        list.add(new Car("大众", 100000));

        System.out.println("===增强for循环===");
        for (Object o : list) {
            System.out.println(o);
        }

        System.out.println("===迭代器===");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object car = iterator.next();
            System.out.println(car);
        }

    }
}
class Car{
    private String name;
    private int price;

    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}